<template>
	<view class="equipment">
		<u-sticky bgColor="#fff">
			<view class="u-page__tag-item">
				<u-search :placeholder="$t('node.name1')" v-model="search" :actionText="$t('node.name11')" @search="handleSearch"
					@custom="handleSearch"></u-search>
			</view>
		</u-sticky>

		<scroll-view scroll-y="true">
			<view v-if="equipmentInfo.count!=0">
				<view class="top_equipment">
					<view class="top_item" v-for="(item,index) in  equipment" :key="index">
						<view class="num" :style="{color:index==3?item.color:''}">
							{{equipmentInfo[item.value]}}
						</view>
						<view class="title">
							{{item.title}}
						</view>
						<view class="circular" :style="{background:item.color}">

						</view>
					</view>
				</view>
				<view class="equipment_box">
					<!-- 			<view class="top_box">
								<view class="l">
									<image src="/static/newProject/equipment/equipment1.png" mode=""></image>
									<text>分组管理</text>
								</view>
								<view class="r">
									<text  @click="jump('./add')">添加 [+]</text>
								</view>
							</view> -->
					<view class="cenetr_box">
						<!-- <view class="l">
									默认分组（6）
								</view> -->
						<view class="r">
							<text>{{$t('node.name2')}}：{{equipmentInfo.totalIncome}}</text>
							<!-- <image src="/static/newProject/equipment/icon_b.png" mode=""></image> -->
						</view>
						<view class="r">
							<text>{{$t('node.name3')}}{{equipmentInfo.yesterIncome}}</text>
							<!-- <image src="/static/newProject/equipment/icon_b.png" mode=""></image> -->
						</view>
					</view>
					<view class="cenetr_box" style="margin-top: 10rpx;">
						<!-- <view class="l">
									默认分组（6）
								</view> -->
						<view class="r">
							<text>{{$t('node.name4')}} ：{{equipmentInfo.totalNode}}</text>
							<!-- <image src="/static/newProject/equipment/icon_b.png" mode=""></image> -->
						</view>
						<view class="r">
							<text>{{$t('node.name5')}}{{equipmentInfo.yesterNode}}</text>
							<!-- <image src="/static/newProject/equipment/icon_b.png" mode=""></image> -->
						</view>
					</view>
					<view class="equipment_list">
						<view v-for="(item,index) in list" :key="index">

							<view class="equipment_item black"
								:style="{background: item.onlineCode=='0' ? '#f6f6f6' : item.onlineCode=='1'?'#f6f6f6':'rgba(255, 0, 0,.3)',color:item.onlineCode=='1'?'#ccc':''}"
								@click="jump(`/pageC/${item.type==0?'equipmentDetail':'equipmentDetail1'}?name=${item.sn}&onlineCode=${item.onlineCode}`)">
								<!-- <view class="equipment_item black"  v-if="item.onlineCode==1"> -->
								<view class="l">
									<image :src="item.image" mode=""></image>
									<view class="center_info">
										<view class="text">
											{{item.sn}}
										</view>
										<view class="text1">
											{{item.mobile}}
										</view>
										<view class="text1">
											{{item.desc ? item.desc: ''}}
										</view>
									</view>
								</view>
								<view class="r">
									<text>+{{item.income}}</text>
									<image src="/static/newProject/equipment/icon_r.png" mode=""></image>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view v-else>
				<view class="noneDate_box">
					<image src="/static/newProject/equipment_none.png" mode=""></image>
					<view class="button">
						{{$t('node.name6')}}
					</view>
				</view>
			</view>
		</scroll-view>
		<!-- 		<view style="height: 170upx;">

		</view>
		<TabBar :tabBarShow="1"></TabBar> -->
	</view>
</template>

<script>
	import headerTop from "@/components/dacizi-headtag/dacizi-headtag.vue"
	export default {
		components: {
			headerTop
		},
		data() {
			return {
				equipment: [{
						title: this.$t('node.name10'),
						value: 'count',
						color: '#FFFFFF'
					},
					{
						title: this.$t('node.name7'),
						value: 'online',
						color: '#00FF00'
					},
					{
						title: this.$t('node.name8'),
						value: 'offline',
						color: '#A0A0A0'
					},
					{
						title: this.$t('node.name9'),
						value: 'fault',
						color: '#FF0000'
					},
				],
				list: [],
				page: 1,
				limit: 20,
				equipmentInfo: {
					count: 0
				},
				search: '',
			}
		},
		onLoad(options) {
			uni.setNavigationBarTitle({
				title: options.name
			})
			this.list = []
			this.page = 1
			this.getUserSnList(this.page, this.limit)
		},
		// onShow() {
		// 	this.list = []
		// 	this.page = 1
		// 	this.getUserSnList(this.page, this.limit)
		// 	this.getGroupList()
		// },
		// onNavigationBarButtonTap(e) {
		// 	this.$fun.jump('./add')
		// },
		// onShow() {
		// 	this.$fun.ajax.post('butt/userSnList', {
		// 		type: 2
		// 	}).then(res => {
		// 		this.equipmentInfo = res.data
		// 		if (res.data.list.length > 0) {
		// 			this.list.push(...res.data.list);
		// 			// this.addressList = res.data
		// 			this.page++
		// 		} else {
		// 			if (this.page != 1) {
		// 				this.$fun.msg('没有更多数据了...')
		// 			}
		// 		}
		// 	})
		// },
		onReachBottom() {
			if (this.page != 1) {
				this.getUserSnList(this.page, this.limit)
			}
		},
		onNavigationBarButtonTap(e) {
			this.$fun.jump('/pageC/add')
		},
		// onShow() {

		// },
		methods: {
			// 搜索
			handleSearch() {
				this.page = 1
				this.limit = 20
				this.list = []
				this.getUserSnList(this.page, this.limit)
			},
			jump(url) {
				this.$fun.jump(url)
			},
			getUserSnList(page, limit) {
				this.$fun.ajax.post('butt/userSnList', {
					type: 2,
					page,
					limit,
					search: this.search
				}).then(res => {
					this.equipmentInfo = res.data
					if (res.data.list.length > 0) {
						this.list.push(...res.data.list);
						// this.addressList = res.data
						this.page++
					} else {
						if (this.page != 1) {
							this.$fun.msg(this.$t('nomore'))
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.equipment {
		.u-page__tag-item {
			padding: 20rpx 20rpx;
		}

		.top_equipment {
			width: 100%;
			height: 180rpx;
			background: #F6F6F6;
			box-sizing: border-box;
			padding: 0 40rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.top_item {
				width: 150rpx;
				height: 150rpx;
				background: #FFFFFF;
				box-shadow: 0rpx 0rpx 20rpx 0rpx rgba(0, 0, 0, 0.05);
				border-radius: 10rpx;
				position: relative;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				font-family: Microsoft YaHei;
				color: #333333;
				font-size: 30rpx;

				.num {
					margin-bottom: 20rpx;
					font-weight: bold;
				}

				.circular {
					position: absolute;
					top: 15rpx;
					right: 15rpx;
					width: 15rpx;
					height: 15rpx;
					border-radius: 50%;
				}
			}
		}

		.equipment_box {
			padding: 41rpx 30rpx;

			.top_box {
				display: flex;
				align-items: center;
				justify-content: space-between;

				.l {
					display: flex;
					align-items: center;

					image {
						margin-left: 13rpx;
						margin-right: 10rpx;
						width: 33rpx;
						height: 38rpx;
					}

					text {
						font-size: 20rpx;
						font-family: Microsoft YaHei;
						font-weight: bold;
						color: #333333;
					}
				}

				.r {
					font-size: 20rpx;
					font-family: Microsoft YaHei;
					font-weight: bold;
					color: #333333;
				}
			}

			.cenetr_box {
				margin-top: 29rpx;
				height: 80rpx;
				background: #EEEEEE;
				border-radius: 10px;
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 0 30rpx;
				box-sizing: border-box;

				.l {
					font-size: 20rpx;
					font-family: Microsoft YaHei;
					font-weight: bold;
					color: #333333;
				}

				.r {
					font-size: 20rpx;
					font-family: Microsoft YaHei;
					font-weight: bold;
					color: #5990FF;

					image {
						margin-left: 90rpx;
						width: 24rpx;
						height: 14rpx;
					}
				}
			}

			.equipment_list {
				margin-top: 20rpx;

				.equipment_item {
					margin-bottom: 20rpx;
					width: 100%;
					padding: 25rpx 30rpx;
					border-radius: 10rpx;
					box-sizing: border-box;
					display: flex;
					justify-content: space-between;

					.l {
						display: flex;

						image {
							width: 80rpx;
							height: 80rpx;
							border-radius: 10rpx;
						}

						.center_info {
							margin-left: 14rpx;
							display: flex;
							flex-direction: column;
							width: 400rpx;

							.text {
								width: 400rpx;
								width: 100%; //固定宽度
								overflow: hidden; //溢出隐藏
								white-space: nowrap; //不换行
								text-overflow: ellipsis; //显示...
							}

						}
					}

					.r {
						display: flex;
						justify-content: flex-end;
						align-items: center;

						text {
							font-size: 24rpx;
							font-family: Microsoft YaHei;
							font-weight: 400;
							color: #5990FF;
						}

						image {
							margin-left: 22rpx;
							width: 14rpx;
							height: 24rpx;
						}
					}
				}

				.gray {
					background: #F6F6F6;
					color: #CCCCCC;
				}

				.black {
					background: #F6F6F6;
					color: #333333;
				}
			}
		}

	}

	.noneDate_box {
		margin-top: 126rpx;
		text-align: center;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;

		image {
			width: 309rpx;
			height: 317rpx;
		}

		.button {
			margin: 30rpx 0;
			width: 200rpx;
			height: 60rpx;
			background: linear-gradient(-30deg, #5990FF 0%, #00aaff 100%);
			border-radius: 30rpx;
			font-size: 22rpx;
			font-family: Microsoft YaHei;
			color: #FFFFFF;
			line-height: 60rpx;
			text-align: center;
		}
	}
</style>